#ifndef ITEMFACTORYMODEL_H
#define ITEMFACTORYMODEL_H

#include <QAbstractItemModel>
#include "collections/dualcollection.h"
#include "other/gameStructs.h"
#include "other/yalb_abstracttreemodel.h"

class RosterUnit;

class ItemFactoryModelItem : public yALB_AbstractTreeItem {
    friend class ItemFactoryModel;
public:

    ItemFactoryModelItem(const QString& _key, yALB_AbstractTreeItem *parent);

    const QString key;

    ItemFactoryModelItem* parent() const;
    ItemFactoryModelItem* child(int i) const;
};

class ItemFactoryModel : public yALB_AbstractTreeModel
{
    Q_OBJECT
public:
    ItemFactoryModel(const DualCollection<GameItem> *items, const DualCollection<GameCategory> *categories,
                     QObject *parent = 0);
    ~ItemFactoryModel();
    
    QVariant data(const QModelIndex &index, int role) const;
    QVariant headerData(int section, Qt::Orientation orientation,
                        int role = Qt::DisplayRole) const;
    int columnCount(const QModelIndex &parent = QModelIndex()) const;

    void setSource(const RosterUnit *unit);
    void buildCategoryIndex();

    QString getItemKeyFromIndex(QModelIndex index) const;

signals:
    
public slots:
    
private:
    const DualCollection<GameItem> *_items;
    const DualCollection<GameCategory> *_categories;

    QHash<QString, QStringList> categoryItems; // Item list (keys) for each category (key)

    enum {NameColumn = 0, CostColumn, ColumnNumber};
};

#endif // ITEMFACTORYMODEL_H
